package util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

public class Util {
    static SqlSessionFactory factory;
    static {
        SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
        try {
            factory=builder.build(Resources.getResourceAsStream("day2/my-config.xml"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static SqlSession getSession(){
        return factory.openSession();
    }
    public static void closeSession(SqlSession session){
        session.close();
    }
}
